var a = getApp(), t = require("../../mybehaviors/location/location");

Page({
    behaviors: [ t ],
    data: {
        language: "",
        name: "",
        page: 1
    },
    onLoad: function(t) {
        var e = this, n = {};
        this._getLocation(function(t, o) {
            n = a.qqMapTransBMap(parseFloat(o.lng), parseFloat(o.lat)), e.setData({
                lat: n.lat,
                lng: n.lng
            }), e.getData(n.lat, n.lng, e.data.city);
        });
    },
    search: function(a) {
        console.log(a.detail.value), this.setData({
            name: a.detail.value
        });
    },
    gosearch: function() {
        var a = this.data.lat, t = this.data.lng;
        wx.navigateTo({
            url: "/packageD/easyRefuel/easyRefuel_list/easyRefuel_list?lat=" + a + "&lng=" + t + "&name=" + this.data.name
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {},
    tolocation: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation/o2oLocation?tag=easyRefuel"
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.current_page >= this.data.last_page ? wx.showToast({
            title: "暂无更多",
            duration: 1e3,
            icon: "none"
        }) : (this.setData({
            page: this.data.page + 1
        }), this.getNextData());
    },
    onShareAppMessage: function() {},
    getData: function(t, e, n) {
        var o = this, i = a.getNetAddresss("plugin.easy-refuel.frontend.index.index"), d = {
            lng: e,
            lat: t,
            name: "",
            cityName: n,
            page: o.data.page
        };
        a._postNetWork({
            url: i,
            data: d,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    for (var e = 0; e < t.data.data.data.length; e++) {
                        t.data.data.data[e].distance = t.data.data.data[e].distance.toFixed(2) + "km";
                        for (var n = 0; n < t.data.data.data[e].prices.length; n++) t.data.data.data[e].prices[n].muns = (Number(t.data.data.data[e].prices[n].discountPrice) - Number(t.data.data.data[e].prices[n].countryPrice)).toFixed(2);
                    }
                    o.setData({
                        banner: t.data.banner,
                        datas: t.data.data.data,
                        shopName: t.data.shopName,
                        last_page: t.data.data.last_page,
                        current_page: t.data.data.current_page
                    }), wx.setNavigationBarTitle({
                        title: t.data.shopName
                    });
                } else 1 == t.data.bindPhone ? (wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                }), wx.navigateTo({
                    url: "/packageA/member/editmobile/editmobile"
                })) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    }
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getNextData: function() {
        var t = this.data.point, e = t.lat, n = t.lng, o = this.data.city, i = this, d = a.getNetAddresss("plugin.easy-refuel.frontend.index.index"), s = {
            lng: n,
            lat: e,
            name: "",
            cityName: o,
            page: i.data.page
        };
        a._postNetWork({
            url: d,
            data: s,
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    for (var e = 0; e < t.data.data.data.length; e++) {
                        t.data.data.data[e].distance = t.data.data.data[e].distance.toFixed(2) + "km";
                        for (var n = 0; n < t.data.data.data[e].prices.length; n++) t.data.data.data[e].prices[n].muns = (Number(t.data.data.data[e].prices[n].discountPrice) - Number(t.data.data.data[e].prices[n].countryPrice)).toFixed(2);
                    }
                    i.setData({
                        banner: t.data.banner,
                        datas: i.data.datas.concat(t.data.data.data),
                        shopName: t.data.shopName,
                        last_page: t.data.data.last_page,
                        current_page: t.data.data.current_page
                    }), wx.setNavigationBarTitle({
                        title: t.data.shopName
                    });
                } else 1 == t.data.bindPhone ? (wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                }), wx.navigateTo({
                    url: "/packageA/member/editmobile/editmobile"
                })) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1e3);
                    }
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    }
});